import axios from "axios"

//   收藏夹

//   创建收藏夹
async function CreateCollect(collectName){
  var result
  await axios({
      baseURL: 'api/collect/create?collectName='+collectName,
      method: 'post',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}

//   查看我的收藏夹列表
async function MyCollectList(){
  var result
  await axios({
      baseURL: 'api/collect/mycollectlist',
      method: 'get',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}

// 根据收藏夹id获取收藏夹歌单id列表
async function GetCollectMusicIds(collectId){
  var result
  await axios({
      baseURL: 'api/collect/getcollectmusicids/'+collectId,
      method: 'get',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}


//   修改收藏夹名称
async function UpdateCollectName(userCollect){
  var result
  await axios({
      baseURL: 'api/collect/updatecollectname',
      headers: {'Content-Type': 'application/json;charset=UTF-8' },
      data: userCollect,
      method: 'put',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}


//    删除收藏夹
async function deleteCollect(collectId){
  var result
  await axios({
      baseURL: 'api/collect/deletecollect?collectId='+collectId,
      method: 'delete',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}


  //    将音乐加入收藏夹
async function AddMusic2Collect(TbCollect){
  var result
  await axios({
      baseURL: 'api/collect/addmusic2collect',
      headers: {'Content-Type': 'application/json;charset=UTF-8' },
      data: TbCollect,
      method: 'post',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}

   //    将音乐移出收藏夹
   async function DeleteMusic2Collect(collect){
    var result
    await axios({
        baseURL: 'api/collect/deletemusic2collect',
        headers: {'Content-Type': 'application/json;charset=UTF-8' },
        data: collect,
        method: 'delete',
    }).then(res => {
        result=res.data
        console.log(result);
    })
    return result
  }
  
//  //    获取收藏夹音乐总数
async function CountMusic2Collect(collectId){
  var result
  await axios({
      baseURL: 'api/collect/count/'+collectId,
      method: 'get',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}
// getMyCollectMsicuListById

async function GetMyCollectMsicuListById(collectId){
  var result
  await axios({
      baseURL: 'api/collect/getmsiculist/'+collectId,
      method: 'get',
  }).then(res => {
      result=res.data
      console.log(result);
  })
  return result
}


export default {
  name: 'CollectAPI',
  CreateCollect,
  MyCollectList,
  GetCollectMusicIds,
  UpdateCollectName,
  deleteCollect,
  AddMusic2Collect,
  DeleteMusic2Collect,
  CountMusic2Collect,
  GetMyCollectMsicuListById
}
